package araujoCoronelVillamayor.plantasVsZombies.uiWicket;

import araujoCoronelVillamayor.plantasVsZombies.appModelsArena.AlmanaqueAppModel;
import araujoCoronelVillamayor.plantasVsZombies.appModelsArena.SesionAppModel;
import araujoCoronelVillamayor.plantasVsZombies.uiWicket.JardinPage;
import araujoCoronelVillamayor.plantasVsZombies.uiWicket.layouts.LayoutPrincipal;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.model.CompoundPropertyModel;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.uqbar.wicket.xtend.WicketExtensionFactoryMethods;
import org.uqbar.wicket.xtend.XButton;
import org.uqbar.wicket.xtend.XLink;
import org.uqbar.wicket.xtend.XListView;

@SuppressWarnings("all")
public class AlmanaquePage extends LayoutPrincipal {
  @Extension
  private WicketExtensionFactoryMethods _wicketExtensionFactoryMethods = new Function0<WicketExtensionFactoryMethods>() {
    public WicketExtensionFactoryMethods apply() {
      WicketExtensionFactoryMethods _wicketExtensionFactoryMethods = new WicketExtensionFactoryMethods();
      return _wicketExtensionFactoryMethods;
    }
  }.apply();
  
  private final AlmanaqueAppModel almanaqueAppModel;
  
  public AlmanaquePage(final JardinPage mainPage) {
    super();
    SesionAppModel _sesion = mainPage.getSesion();
    AlmanaqueAppModel _almanaqueAppModel = new AlmanaqueAppModel(_sesion);
    this.almanaqueAppModel = _almanaqueAppModel;
    CompoundPropertyModel<AlmanaqueAppModel> _compoundPropertyModel = new CompoundPropertyModel<AlmanaqueAppModel>(this.almanaqueAppModel);
    this.setDefaultModel(_compoundPropertyModel);
    CompoundPropertyModel<AlmanaqueAppModel> _compoundPropertyModel_1 = new CompoundPropertyModel<AlmanaqueAppModel>(this.almanaqueAppModel);
    Form<AlmanaqueAppModel> _form = new Form<AlmanaqueAppModel>("formAlmanaque", _compoundPropertyModel_1);
    Form<AlmanaqueAppModel> formAlmanaque = _form;
    this.agregarGrillaResultados(formAlmanaque);
    this._wicketExtensionFactoryMethods.addChild(this, formAlmanaque);
    XLink<Object> _xLink = new XLink<Object>("volverJardin");
    final Procedure1<XLink<Object>> _function = new Procedure1<XLink<Object>>() {
      public void apply(final XLink<Object> it) {
        final Procedure0 _function = new Procedure0() {
          public void apply() {
            it.setResponsePage(mainPage);
          }
        };
        it.setOnClick(_function);
      }
    };
    XLink<Object> _doubleArrow = ObjectExtensions.<XLink<Object>>operator_doubleArrow(_xLink, _function);
    this._wicketExtensionFactoryMethods.addChild(this, _doubleArrow);
    this.almanaqueAppModel.buscar();
  }
  
  /**
   * Se agrega a la grilla los resultados de la busqueda del Zombie buscado
   */
  public MarkupContainer agregarGrillaResultados(final Form<AlmanaqueAppModel> form) {
    MarkupContainer _xblockexpression = null;
    {
      XListView<Object> _xListView = new XListView<Object>("resultadoBusqueda");
      final XListView<Object> listViewAtaque = _xListView;
      final Procedure1<ListItem<Object>> _function = new Procedure1<ListItem<Object>>() {
        public void apply(final ListItem<Object> item) {
          Object _modelObject = item.getModelObject();
          CompoundPropertyModel<Object> _asCompoundModel = AlmanaquePage.this._wicketExtensionFactoryMethods.<Object>asCompoundModel(_modelObject);
          item.setModel(_asCompoundModel);
          Label _label = new Label("nombre");
          AlmanaquePage.this._wicketExtensionFactoryMethods.addChild(item, _label);
          Label _label_1 = new Label("ataque");
          AlmanaquePage.this._wicketExtensionFactoryMethods.addChild(item, _label_1);
          Label _label_2 = new Label("defensa");
          AlmanaquePage.this._wicketExtensionFactoryMethods.addChild(item, _label_2);
        }
      };
      listViewAtaque.setPopulateItem(_function);
      this._wicketExtensionFactoryMethods.addChild(form, listViewAtaque);
      TextField<String> _textField = new TextField<String>("zombieBuscado");
      this._wicketExtensionFactoryMethods.addChild(form, _textField);
      XButton _xButton = new XButton("buscar");
      final Procedure1<XButton> _function_1 = new Procedure1<XButton>() {
        public void apply(final XButton it) {
          final Procedure0 _function = new Procedure0() {
            public void apply() {
              AlmanaquePage.this.almanaqueAppModel.buscar();
            }
          };
          it.setOnClick(_function);
        }
      };
      XButton _doubleArrow = ObjectExtensions.<XButton>operator_doubleArrow(_xButton, _function_1);
      this._wicketExtensionFactoryMethods.addChild(form, _doubleArrow);
      XButton _xButton_1 = new XButton("limpiar");
      final Procedure1<XButton> _function_2 = new Procedure1<XButton>() {
        public void apply(final XButton it) {
          final Procedure0 _function = new Procedure0() {
            public void apply() {
              AlmanaquePage.this.almanaqueAppModel.limpiar();
            }
          };
          it.setOnClick(_function);
        }
      };
      XButton _doubleArrow_1 = ObjectExtensions.<XButton>operator_doubleArrow(_xButton_1, _function_2);
      MarkupContainer _addChild = this._wicketExtensionFactoryMethods.addChild(form, _doubleArrow_1);
      _xblockexpression = (_addChild);
    }
    return _xblockexpression;
  }
}
